package com.em.service;

import com.em.common.model.SysPermission;
import com.em.common.model.SysRole;
import com.em.common.model.SysUser;

import java.util.List;

/**
 * Created by zlx on 2017/12/12 0012.
 */
public class UserService {

    public static UserService me = new UserService();

    public SysUser findUserByUsername(String username){
        return SysUser.dao.findFirst("select * from sys_user where login_account = ?",username);
    }

    public List<SysRole> findUserRoles(Long userId){
        return SysRole.dao.find("select * from sys_role r " +
                " left join sys_user_role ur on r.role_id = ur.role_id " +
                " where ur.user_id = ?",userId);
    }

    public List<SysPermission> findUserPermission(String roleKey){
        return SysPermission.dao.find("select * from sys_permission a" +
                " left join sys_role_permission ra on a.menu_code = ra.menu_code " +
                " where ra.role_key =  ?;",roleKey);
    }
}
